package org.zoomdev.zoom.dao;

import org.zoomdev.zoom.dao.configs.Where;

public interface SqlBuilder {

    char COMMA = ',';  //comma
    char SPACE = ' ';
    String AND = " AND ";
    String OR = " OR ";

    String INNER = "INNER";
    String LEFT = "LEFT";
    String RIGHT = "RIGHT";

    enum JoinType {
        INNER(SqlBuilder.INNER),
        LEFT(SqlBuilder.LEFT),
        RIGHT(SqlBuilder.RIGHT);

        private final String value;

        JoinType(String value) {
            this.value = value;
        }

        public static JoinType parse(String type) {
            if (type == null)
                return INNER;

            type = type.toUpperCase();

            for (JoinType s : values()) {
                if (s.value.equals(type)) {
                    return s;
                }
            }

            return INNER;
        }

        public String value() {
            return value;
        }
    }

    enum Sort {
        ASC("ASC"),
        DESC("DESC");

        private final String value;

        Sort(String value) {
            this.value = value;
        }

        public static Sort parse(String sort) {
            if (sort == null)
                return DESC;

            sort = sort.toUpperCase();

            for (Sort s : values()) {
                if (s.value.equals(sort)) {
                    return s;
                }
            }

            return DESC;
        }

        public String value() {
            return value;
        }

    }

    /**
     * @author jzoom
     */
    enum Like {

        MATCH_BOTH("%%%s%%"),                //like '%{}%'
        MATCH_END("%%%s"),                //like '%{}'
        MATCH_START("%s%%");                //like '{}%'

        private final String format;

        Like(String format) {
            this.format = format;
        }

        public String toValue(Object value) {
            return String.format(format, value);
        }
    }

    enum Join {
        INNER("INNER"),
        LEFT("LEFT"),
        RIGHT("RIGHT");

        private final String value;

        Join(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

    }

    interface Condition {
        void where(Where where);
    }

}
